import { getAreaObj, uploadType } from '@/utils/util'
import { getStore } from '@/utils/store'
import { useDateFormat } from '@vueuse/core'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '处理内容',
			prop: 'disposeContent',
			maxlength: '500',
			showWordLimit: true,
			type: 'textarea',
			span: 24,
			rules: [{ required: true, message: '请输入处理内容' }],
		},
		{
			label: '处理图片',
			prop: 'disposePic',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			changeField: true,
			span: 24,
		},
	],
}
export const dispatchConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'left',
	labelWidth: '100px',
	column: [
		{
			label: '调度安全员',
			prop: 'staffId',
			propName: 'staffName',
			type: 'autoSelect',
			api: 'getSecurityUserPage',
			filterKey: 'userId',
			filterLabel: 'realName',
			multiple: false,
			paramsObj: {},
			span: 24,
			rules: [{ required: true, message: '请选择调度安全员' }],
			change: (item, form) => {
				form.staffIdCard = item.idCard || item.idNo
			},
		},
		{
			label: '紧急类型',
			prop: 'urgentType',
			propName: 'urgentTypeLabel',
			type: 'select',
			dicData: [
				{ label: '一般', value: '1' },
				{ label: '紧急', value: '2' },
			],
			span: 24,
			rules: [{ required: true, message: '请选择紧急类型' }],
		},
	],
}

export const detailConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '报警时间',
			prop: 'alarmTime',
			span: 12,
		},
		{
			label: '报警原因',
			prop: 'alarmReasonLabel',
			span: 12,
		},
		{
			label: '所属区',
			prop: 'areaName',
			span: 12,
		},
		{
			label: '所属单位',
			prop: 'organizationName',
			span: 12,
		},
		{
			label: '是否处理',
			prop: 'isDispose',
			type: 'select',
			dicData: [
				{
					label: '已处理',
					value: 1,
					type: 'success',
				},
				{
					label: '未处理',
					value: 2,
					type: 'danger',
				},
			],
			span: 12,
		},
		{
			label: '处理人',
			prop: 'disposeUserName',
			span: 12,
		},
		{
			label: '处理时间',
			prop: 'disposeTime',
			span: 12,
		},
		{
			label: '处理内容',
			prop: 'disposeContent',
			maxlength: '500',
			showWordLimit: true,
			type: 'textarea',
			span: 24,
		},
		{
			label: '处理图片',
			prop: 'disposePic',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			changeField: true,
			span: 24,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '报警时间',
			prop: 'alarmTimeBetween',
			type: 'dateBetween',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
		{
			label: '报警原因',
			prop: 'alarmReason',
			type: 'remoteSelect',
			code: 'OST_ALARM_REASON',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '所属地区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '所属单位',
			prop: 'organizationName',
			type: 'input',
			span: 8,
		},
		{
			label: '处理状态',
			prop: 'isDispose',
			type: 'select',
			dicData: [
				{
					label: '已处理',
					value: 1,
					type: 'success',
				},
				{
					label: '未处理',
					value: 2,
				},
			],
			span: 8,
		},
		{
			label: '处理时间',
			prop: 'disposeTimeBetween',
			type: 'dateBetween',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '报警时间', prop: 'alarmTime' },
		{ label: '报警原因', prop: 'alarmReasonLabel' },
		{ label: '所属区', prop: 'areaName' },
		{ label: '所属单位', prop: 'organizationName' },
		{
			label: '处理状态',
			prop: 'isDispose',
			custome: 'tag',
			dicData: [
				{
					label: '已处理',
					value: 1,
					type: 'success',
				},
				{
					label: '未处理',
					type: 'danger',
					value: 2,
				},
			],
		},
		{ label: '处理人', prop: 'disposeUserName' },
		{ label: '处理时间', prop: 'disposeTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_pbAlarm_page',
	edit: 'view_pbAlarm_edit',
	delete: 'view_pbAlarm_del',
	detail: 'view_pbAlarm_view',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '报警事件管理',
	dictcodes: ['OST_ALARM_REASON'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'alarmTime',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	paramsObj: {
		alarmType: 1,
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '处理',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
			condition: `(row) => { return row.isDispose === 2 }`,
		},
		{
			icon: 'editor',
			label: '调度',
			type: 'primary',
			operate: 'dispatch',
			auth: 'view_pbDispatch_add',
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				...areaObj,
				areas: undefined,
			})
		})
	},
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const userInfo = getStore('userInfo') || {}
			const newDate = useDateFormat(new Date(), 'YYYY-MM-DD HH:mm:ss')
			form.disposeTime = newDate.value
			form.disposeUserId = userInfo.id
			form.disposeUserName = userInfo.realName
			form.isDispose = 1
			resolve(form)
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			resolve(arr)
		})
	},
	dialogConfig: {
		width: '75%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	detailConfig,
}
